#ifndef USER_H
#define USER_H

#include <qstring.h>
#include <OrmBase.h>
#include <QVariantMap>

class User : public OrmBase {
    Q_OBJECT
    /**
     * @property id
     * @brief 用户ID属性 - 对外名称为 id，内部存储为 id
     * - 属性名: id (在QML和property()函数中使用)
     * - 成员变量: id (类内部实际存储的变量)
     * - 访问 property("id").toInt(); 对外名称为 id
     * - 设置 setProperty("id", 25);对外名称为 id
     */
    Q_PROPERTY(int id MEMBER id)
    Q_PROPERTY(QString name MEMBER name)
    Q_PROPERTY(int age MEMBER age)
public:
    int id;
    QString name;
    int age;
    explicit User(QObject *parent = nullptr) : OrmBase(parent) {};
    User(const QString &name, int age) : id(0), name(name), age(age) {};
    User(const QString &name, int age, QObject *parent = nullptr)
        : OrmBase(parent), id(0), name(name), age(age) {}

    QString tableName() const override { return "user"; }

    QVariantMap toMap() const override {
        QVariantMap map;
        map["name"] = name;
        map["age"] = age;
        return map;
    }

    void fromMap(const QVariantMap &map) override {
        id = map.value("id").toInt();
        name = map.value("name").toString();
        age = map.value("age").toInt();
    }
};

#endif // USER_H
